# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def user
    @user=session[:user]
  end

  def categories
    user.categories
  end

  def uncategoried
    user.uncategoried
  end

  # Return an Array of available categories, uncategoried is special
  def category_choices
    categories.map{ |c| [c.title,c.id]}.push(['Uncategoried', -1])
  end

  def show_subscription_option
    page.replace_html('subscription_option', :partial => 'shared/subscription_option',
                      :object => @subscription)
    page.show 'subscription_option'
  end

  def hide_subscription_option
    page.hide 'subscription_option'
  end

  def show_subscription_title
    page.replace_html('subscription_title', :partial => 'shared/subscription_title')
  end

  # Add parameters when "Show all" or "Show only new" clicked
  def add_option(option)
    if @category
      option[:is_category]=true
      option[:show_id]=@category.id
    elsif @subscription
      option[:show_id]=@subscription.id
    end
    return option
  end

  def mark_url
    if @category
      mark_category_url(@category)
    elsif @subscription
      mark_subscription_url(@subscription)
    end
  end

  def refresh_nav
    page.replace_html 'nav', :partial => 'shared/nav'
  end

  # When empty subscription or category
  def empty_items
    page.replace_html 'items', :partial => 'shared/empty'
  end

  # Display articles in the right
  def show_items(item_data)
    unless item_data.empty?
      page.replace_html('items', :partial => 'shared/item_data',
                        :collection => item_data)
    else
      page.empty_items
    end
    page.show_options
  end

  def show_options
    page.show_subscription_option
    page.show_subscription_title
  end

  def refresh_subscription_nav(subscription)
    page.replace_html subscription.div_id, :partial => 'shared/subscription_select', :object => subscription
    page.visual_effect(:highlight, subscription.div_id,:duration => 3)
  end

  def hide_marked_item(unreaded)
    page.visual_effect(:blind_up, unreaded.item.div_id, :duration => 0.5)
  end



end
